package cn.keniykey.mc.viewlibrary.container.api;

import javax.annotation.Nullable;

import org.bukkit.event.inventory.InventoryType;

public enum EContainerType {
	GENERIC_1X9(0,9),
	GENERIC_2X9(1,18),
	GENERIC_3X9(2,27),
	GENERIC_4X9(3,36),
	GENERIC_5X9(4,45),
	GENERIC_6X9(5,54),
	GENERIC_3X3(6,9),
	ANVIL(7,3), //铁毡，0到2，共3格物品
//	BEACON(8,1), //信标
//	BLAST_FURNACE(9,3), //高炉
//	BREWING_STAND(10,5), //炼药台
	CRAFTING_TABLE(11,10),//工作台, 0到9，共10格物品
	ENCHANTMENT_TABLE(12,2),//附魔台, 0到1，共2格物品
//	FURNACE(13,3), //熔炉
//	GRINDSTONE(14,3), //磨石
	HOPPER(15,5),//漏斗，0到4，共5格物品
	//丢失16
	LOOM(17,4),//织布机,0到3，共4格物品
//	MERCHANT(18,3), //商人
//	SHULKER_BOX(19,27), //潜影盒
//	SMOKER(20,3), //烟熏熔炉
//	CARTOGRAPHY_TABLE(21,3), //制图台
	STONECUTTER(22,2);//切石机 0到1，共2格物品
	
	private final int container_id;
	private final int container_max_capacity;
	
	private EContainerType(int id,int max) {
		this.container_id = id;
		this.container_max_capacity = max;
	}
	
	public int getContainerID() {
		return this.container_id;
	}
	public int getContainerMaxCapacity() {
		return this.container_max_capacity;
	}
	public InventoryType toBukkitInventoryType() {
		try {
			switch(this)
			{
			case GENERIC_1X9:
			case GENERIC_2X9:
			case GENERIC_3X9:
			case GENERIC_4X9:
			case GENERIC_5X9:
			case GENERIC_6X9:
				return InventoryType.CHEST;
			case GENERIC_3X3:
			case HOPPER:
				return InventoryType.HOPPER;
			case ANVIL:
				return InventoryType.ANVIL;
			case CRAFTING_TABLE:
				return InventoryType.CRAFTING;
			case ENCHANTMENT_TABLE:
				return InventoryType.ENCHANTING;
			case LOOM:
				return InventoryType.valueOf("LOOM");
			case STONECUTTER:
				return InventoryType.valueOf("STONECUTTER");
			}
		}catch(NullPointerException ex) {
			throw new NullPointerException("This version does not support the container(这个版本不支持 "  + this.toString() + ")");
		}
		throw new NullPointerException("Unknown ContainerType(未知的类型)");
	}
	public static EContainerType matchContainer(int size) {
		final int line = size/10;
		switch(line) {
		case 0: 
			return GENERIC_1X9;
		case 1: 
			return GENERIC_2X9;
		case 2: 
			return GENERIC_3X9;
		case 3: 
			return GENERIC_4X9;
		case 4: 
			return GENERIC_5X9;
		case 5: 
			return GENERIC_6X9;
		default:
		}
		throw new RuntimeException("out of the max allow range(超出最大许可范围)");
	}
	@Nullable
	public static EContainerType coverEContainerType(String str_nms_container_name) {
		switch(str_nms_container_name) {
		case "GENERIC_9X1": return EContainerType.GENERIC_1X9;
		case "GENERIC_9X2": return EContainerType.GENERIC_2X9;
		case "GENERIC_9X3": return EContainerType.GENERIC_3X9;
		case "GENERIC_9X4": return EContainerType.GENERIC_4X9;
		case "GENERIC_9X5": return EContainerType.GENERIC_5X9;
		case "GENERIC_9X6": return EContainerType.GENERIC_6X9;
		case "GENERIC_3X3": return EContainerType.GENERIC_3X3;
		case "ANVIL": return EContainerType.ANVIL;
		case "CRAFTING": return EContainerType.CRAFTING_TABLE;
		case "ENCHANTMENT": return EContainerType.ENCHANTMENT_TABLE;
		case "HOPPER": return EContainerType.HOPPER;
		case "LOOM": return EContainerType.LOOM;
		case "STONECUTTER": return EContainerType.STONECUTTER;
		}
		return null;
	}
}